import React, { Component } from 'react'
import './css/11-实例选项卡.css'
import Film from './maizuoComponent/Film'
import Cinema from './maizuoComponent/Cinema'
import Center from './maizuoComponent/Center'
export default class App extends Component {
    state={
        list:[
            {id:1,text:"电影"},
            {id:2,text:"影院"},
            {id:3,text:"我的"} 
        ],
        current:0
    }
    handleClick(index){
        // console.log(index);
        this.setState({
            current:index
        })
      }
      switchTab=()=>{
        switch(this.state.current){
            case 0:
                return <Film></Film>
            case 1:
                return <Cinema></Cinema>
            case 2:
                return <Center></Center>
            default:
                return null
        }
      }
  render() {
    return (
      <div>
        {/* 第一种渲染组件 */}
        {/* {this.state.current===0 &&<Film></Film>}
        {this.state.current===1 &&  <Cinema></Cinema>}
        {this.state.current===2 &&  <Center></Center>} */}
        {/* 第二种渲染组件 */}
        {this.switchTab()}
        <ul>
            {
                this.state.list.map((item,index)=>
                <li 
                    key={item.id} 
                    className={this.state.current===index?"active":''}
                    onClick={()=>this.handleClick(index)}
                    >{item.text}</li>
                )
            }
        </ul>
      </div>
    )
  }

}
